<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.netcombine.freewill.constants.*, com.netcombine.freewill.vo.FreewillVo, com.netcombine.freewill.lib.Paging, com.netcombine.freewill.vo.PagingVo" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%

//저장후 로직
String resultCD= request.getAttribute("resultCD") == null ? "" : (String)request.getAttribute("resultCD");

if(resultCD.equals("duplication")){
%>
<script>
	alert("아이디가 중복되었습니다.");
</script>
<%
}else if(resultCD.equals("insert")){
%>
<script>
	alert("저장되었습니다.");
</script>
<%
}else if(resultCD.equals("update")){
%>
<script>
	alert("수정 되었습니다.");
</script>
<%
}else if(resultCD.equals("delete")){
%>
<script>
	alert("삭제 되었습니다.");
</script>
<%
}

Paging paging = (Paging)request.getAttribute("paging");



int total_cnt = paging.getTotalCnt();
String idx = "";
%>



<html>
<head>

<title><%=PageInfo.TITLE%> - 관리자</title>
<tiles:insertDefinition name="_head" />

</head>

<body>
<script>
function insertFrm(){
	var frm = document.memberForm;
	if(frm.admin_id.value == ""){
		alert("아이디를 입력하세요");
		frm.id.focus();
		return;
	}
	if(frm.admin_pw.value == ""){
		
		alert("비밀번호를 입력하세요");
		frm.pwHash.focus();
		return;
	}
	if(frm.admin_name.value == ""){
		
		alert("이름을 입력하세요");
		frm.name.focus();
		return;
	}
	if(!confirm("등록하시겠습니까?")){
		return;
	}
	
	frm.mode.value = "insert";
	frm.action = "<%= request.getContextPath() %>/member/list.do";
	frm.submit();
	
}
function updateFrm(obj, admin_idx){
	var frm = document.memberForm;
	
	//var id = $(obj).parents('tr').find('input[name=id]').val();
	var admin_pw = $(obj).parents('tr').find('input[name=admin_pw]').val();
	var admin_name = $(obj).parents('tr').find('input[name=admin_name]').val();
	var admin_level = $(obj).parents('tr').find('select[name=admin_level] option:selected').val();
	/* 
	if(id.length == 0){
		alert("아이디를 입력하세요");
		return;
	}
	 */
	if(admin_pw.length == 0){
		alert("비밀번호를 입력하세요");
		return;
	}
	 
	if(admin_name.length == 0){
		alert("이름을 입력하세요");
		return;
	}

	if(!confirm("수정 하시겠습니까?")){
		return;
	}
	
	frm.admin_idx.value = admin_idx;
	//frm.id.value = id;
	frm.admin_pw.value = admin_pw;
	frm.admin_name.value = admin_name;
	frm.admin_level.value = admin_level;
	
	frm.mode.value = "update";
	frm.action = "<%= request.getContextPath() %>/member/list.do";
	frm.submit();

}
function deleteFrm(admin_idx){
	var frm = document.memberForm;
	if(!confirm("삭제 하시겠습니까?")){
		return;
	}
	frm.admin_idx.value = admin_idx;
	frm.mode.value = "delete";
	frm.action = "<%= request.getContextPath() %>/member/list.do";
	frm.submit();
	
}
</script>
<div class="wrap">
		
	<tiles:insertDefinition name="_header" />

	<!-- Container -->
	<div class="container">
	<div>
		
		<!-- LNB -->
		<tiles:insertDefinition name="_menu" />
		<!-- LNB  //-->
		
		<!-- Content -->
		<div class="content">
			
			<!-- locatioin -->
		<form name="memberForm" method="POST">
		<input type="hidden" name="admin_idx" value= "<%=idx%>">
		<input type="hidden" name="mode">
			<div class="location">
				<h1>관리자 관리</h1>
				<ul>
					<li class="home"><a href="#none"><span>home</span></a> &gt;</li>
					<li><a href="#none">회원관리</a> &gt;</li>
					<li><strong>관리자 관리</strong></li>
				</ul>
			</div>
			<!-- locatioin // -->

			<!-- member_search -->
			<div class="member_search">
				<table summary="아이디, 패스워드, 이름, 등급">
					<caption>관리자 관리</caption>
					<colgroup>
						<col style="width:;">
						<col style="width:;">
						<col style="width:;">
						<col style="width:;">
						<col style="width:;">
					</colgroup>
					<tbody>
						<tr>
							<th scope="row">아이디</th>
							<th scope="row">패스워드</th>
							<th scope="row">이름</th>
							<th scope="row">등급</th>
							<th scope="row" rowspan="2" class="txtC"><span class="btn_member bgnone"><a href="javascript: insertFrm();">등록</a></span></th>
						</tr>
						<tr>
							
								<td class="txtC"><input type="text" name="admin_id" title="아이디" class="i_text inw8"></td>
								<td class="txtC"><input type="text" name="admin_pw" title="패스워드" class="i_text inw8"></td>
								<td class="txtC"><input type="text" name="admin_name" title="이름" class="i_text inw8"></td>
								<td class="txtC">
									<select name="admin_level">
										<option value="1">관리자</option>
										<option value="2">배송 담당자</option>
										<option value="3">CS 담당자</option>
									</select>
								</td>
												
						</tr>
					</tbody>
				</table>
			</div>
		</form>
			<!-- member_search // -->
			
			<!-- search detail -->
			<div class="search_detail">
				<p class="txt">총 <span><%= total_cnt %></span> 명</p>
			</div>
			<!-- search detail // -->

			<!-- table -->
			<div class="tb_list1 tb_member1">
				<table summary="번호, 아이디, 패스워드, 이름, 등급, 등록일, 수정, 삭제">
					<caption>관리자 관리</caption>
					<colgroup>
						<col style="width:6%;">
						<col style="width:;">
						<col style="width:;">
						<col style="width:;">
						<col style="width:;">
						<col style="width:10%;">
						<col style="width:10%;">
						<col style="width:10%;">
					</colgroup>
					<thead>
					<tr>
						<th scope="col"><div>No.</div></th>
						<th scope="col"><div>아이디</div></th>
						<th scope="col"><div>패스워드</div></th>
						<th scope="col"><div>이름</div></th>
						<th scope="col"><div>등급</div></th>
						<th scope="col"><div>등록일</div></th>
						<th scope="col"><div>수정</div></th>
						<th scope="col"><div>삭제</div></th>
					</tr>
					</thead>
					<tbody>
					<%
						if (total_cnt != 0) {
					%>
						<c:forEach items="${memberList}" var="vo">
							<tr>
								<td><%=total_cnt--%></td>
								<td><input type="text" class="i_text inw8" name="admin_id" value="${vo.admin_id}" readonly="readonly"/></td>
								<td><input type="text" class="i_text inw8" name="admin_pw" /></td>
								<td><input type="text" class="i_text inw8" name="admin_name" value="${vo.admin_name}"/> </td>
								<td>
									<select name="admin_level">
										<option value="1" <c:if test="${vo.admin_level eq '1'}">selected="selected"</c:if>>관리자</option>
										<option value="2" <c:if test="${vo.admin_level eq '2'}">selected="selected"</c:if>>배송 담당자</option>
										<option value="3" <c:if test="${vo.admin_level eq '3'}">selected="selected"</c:if>>CS 담당자</option>
									</select>
								</td>
								<td>${vo.admin_regdate}</td>	
						
								<td><span class="btn_gray1"><a class="updateBtn" onclick="updateFrm(this, '${vo.admin_idx}');">수정</a></span></td>
								<td><span class="btn_blue3"><a href="javascript: deleteFrm('${vo.admin_idx}');">삭제</a></span></td>
						</c:forEach>					
						
					
					<%
							} else {
					%>
						<tr>
							<td colspan="10">항목명을 입력해 주세요.</td>
						</tr>
					<% } %>
				
					</tbody>
				</table>
			</div>
			<!-- table // -->

			<!-- paging -->
			${paging.getPagingHtml()}
			<!-- paging // -->

			</div>
		<!-- Content // -->
		</div>
	</div>
		<!-- Container // -->
</div>
<form name="pageForm" method="POST">
<input type="hidden" name="page" value="${pagingVo.page}"/>


</form>

</body>
</html>